﻿<Page x:Class="TodoList.View.TodoView"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="850" d:DesignWidth="850"
      xmlns:converter="clr-namespace:TodoList.Converter"
      xmlns:viewModel="clr-namespace:TodoList.ViewModel"
	Title="TodoView">
    
    
    <Page.Resources>
        <converter:TodoConverter x:Key="todoConvert" />
        <converter:PriorityConverter x:Key="priorityConvert" />
        <converter:StateConverter x:Key="stateConvert" />
        <converter:CompleteConverter x:Key="completeConvert"/>
        <converter:CompleteColorConverter x:Key="completeColorConvert"/>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="Foreground" Value="WhiteSmoke" />
        </Style>
    </Page.Resources>
    
    <Page.DataContext>
        <viewModel:TodoVM x:Name="todoVm" ></viewModel:TodoVM>
    </Page.DataContext>

    <StackPanel HorizontalAlignment="Center">
        <Expander Margin="2" ExpandDirection="Down" Foreground="Tomato" FontWeight="Black" FontSize="12"
                  IsExpanded="True" Header=" Add Tasks" >            
            <StackPanel>
                <StackPanel Margin="3" Orientation="Horizontal" >
                    
                    <TextBlock Margin="0,10,5,5"  >URL : </TextBlock>
                    <TextBox Margin="5" Height="23" Text="{Binding FileName}" Width="480" />
                    <Button Content="Load" Height="25"  Margin="0,0,5,0"                 
                        CommandParameter="{Binding ElementName=todoVm}"
                        Command="{Binding Path=LoadAction}" />
                    <Button Content="Set as Default File" Height="25"                  
                        CommandParameter="{Binding ElementName=todoVm}"
                        Command="{Binding Path=SetAction}" />
                    
                </StackPanel>
                <Grid ShowGridLines="False">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="180" />
                    <ColumnDefinition Width="100"/>
                    <ColumnDefinition Width="180" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="25" />
                    <RowDefinition Height="25" />
                    <RowDefinition Height="25" />
                    <RowDefinition Height="25" />
                </Grid.RowDefinitions>
                <TextBlock Text="Title" Grid.Column="0" Grid.Row="0" Margin="2"  />
                <TextBlock Text="Description" Grid.Column="0" Grid.Row="1" Margin="2" />
                <TextBlock Text="Due Date" Grid.Column="0" Grid.Row="2" Margin="2" />

                <TextBox Grid.Column="1" Grid.Row="0" Margin="2" 
                         Text="{Binding ElementName=todoVm, Path=Todo.Title, ValidatesOnDataErrors=True, 
	UpdateSourceTrigger=PropertyChanged}"  />
                <TextBox Grid.Column="1" Grid.Row="1" Margin="2" Text="{Binding ElementName=todoVm, Path=Todo.Description}" />
                <DatePicker Grid.Column="1" Grid.Row="2" Margin="2" Text="{Binding ElementName=todoVm, Path=Todo.DueDate}" />

                <TextBlock Text="CompletedStatus" Grid.Column="2" Grid.Row="0" Margin="2" />
                <TextBlock Text="State" Grid.Column="2" Grid.Row="1" Margin="2" />
                <TextBlock Text="Priority" Grid.Column="2" Grid.Row="2" Margin="2" />

                <ComboBox Grid.Column="3" Grid.Row="0" Margin="2" SelectedIndex="{Binding Path=Todo.CompletedStatus}" >
                    <ComboBoxItem>0%</ComboBoxItem>
                    <ComboBoxItem>25%</ComboBoxItem>
                    <ComboBoxItem>50%</ComboBoxItem>
                    <ComboBoxItem>75%</ComboBoxItem>
                    <ComboBoxItem>100%</ComboBoxItem>                    
                </ComboBox>
                <ComboBox Grid.Column="3" Grid.Row="1" Margin="2" 
                          SelectedIndex="{Binding Path=Todo.State}" >
                    <ComboBoxItem>Not Started</ComboBoxItem>
                    <ComboBoxItem>In Progress</ComboBoxItem>
                    <ComboBoxItem>Completed</ComboBoxItem>
                    <ComboBoxItem>Defered</ComboBoxItem>
                </ComboBox>
                <ComboBox Grid.Column="3" Grid.Row="2" Margin="2" SelectedIndex="{Binding Path=Todo.Priority}" >
                    <ComboBoxItem>Immediate</ComboBoxItem>
                    <ComboBoxItem>Medium</ComboBoxItem>
                    <ComboBoxItem>Low</ComboBoxItem>
                    <ComboBoxItem>Normal</ComboBoxItem>
                </ComboBox>

                <Button Content="Save" Grid.Column="3" Grid.Row="3"                        
                        CommandParameter="{Binding ElementName=todoVm}"
                        Command="{Binding Path=SaveCommand}" />

            </Grid>
            </StackPanel>
        </Expander>

        <Border HorizontalAlignment="Left"  CornerRadius="2" BorderThickness="1" BorderBrush="YellowGreen" Width="700">
            <Border.Resources>
                <converter:TodoEditConverter x:Key="editConvert" />
            </Border.Resources>
            <StackPanel  Orientation="Horizontal" Margin="2" >
                <TextBlock Text="Filter By :" Margin="2"/>
                <RadioButton x:Name="rdNotStarted" GroupName="Filter" Margin="2" 
                              Content="Not Started" Tag="0"
                              Command="{Binding Path=FilterAction}"  >
                    <RadioButton.CommandParameter>
                        <MultiBinding Converter="{StaticResource ResourceKey=editConvert}">
                            <Binding ElementName="rdNotStarted" Path="Tag"/>
                            <Binding />
                        </MultiBinding>
                    </RadioButton.CommandParameter> 
                </RadioButton>
                <RadioButton x:Name="rdInProg" GroupName="Filter" Margin="2" 
                               Tag="1"
                              Command="{Binding Path=FilterAction}" Content="In Progress">
                    <RadioButton.CommandParameter>
                        <MultiBinding Converter="{StaticResource ResourceKey=editConvert}">
                            <Binding ElementName="rdInProg" Path="Tag"/>
                            <Binding />
                        </MultiBinding>
                    </RadioButton.CommandParameter>
                </RadioButton>
                <RadioButton x:Name="rdComp" GroupName="Filter" Margin="2" 
                                Tag="2" Content="Completed"
                              Command="{Binding Path=FilterAction}">
                    <RadioButton.CommandParameter>
                        <MultiBinding Converter="{StaticResource ResourceKey=editConvert}">
                            <Binding ElementName="rdComp" Path="Tag"/>
                            <Binding />
                        </MultiBinding>
                    </RadioButton.CommandParameter>
                </RadioButton>
                <RadioButton x:Name="rdDef" GroupName="Filter" Margin="2" 
                               Tag="3" Content="Defered"
                              Command="{Binding Path=FilterAction}">
                    <RadioButton.CommandParameter>
                        <MultiBinding Converter="{StaticResource ResourceKey=editConvert}">
                            <Binding ElementName="rdDef" Path="Tag"/>
                            <Binding />
                        </MultiBinding>
                    </RadioButton.CommandParameter>
                </RadioButton>                
            </StackPanel>
        </Border> 
               
        <ListView  Margin="20,10,10,10" 
                  Name="lstTodos"  
                   Height="400" 
                  IsSynchronizedWithCurrentItem="True"
                 DataContext="{Binding ElementName=todoVm}"                 
                 ItemsSource="{Binding TodoList}">
            <ListView.View>
                <GridView>

                    <!--<GridViewColumn Header="Id"  Width="100">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  TextAlignment="Center" Text="{Binding Path=Id}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>-->
                    
                    <GridViewColumn Header="Title" Width="100" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  TextAlignment="Center" Text="{Binding Path=Title}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    
                    <GridViewColumn Header="Priority" Width="100">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  TextAlignment="Center" Text="{Binding Path=Priority, Converter={StaticResource ResourceKey=priorityConvert}}"  />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="Description"  Width="100" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock  TextAlignment="Center" Height="30"  Text="{Binding Path=Description}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="Due Date"  Width="100">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextAlignment="Center" Text="{Binding Path=DueDate}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="State"  Width="100">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock TextAlignment="Center" Text="{Binding Path=State, Converter={StaticResource ResourceKey=stateConvert}}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="Completed Status"  Width="100">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <ProgressBar 
                                            TextBlock.FontWeight="Bold" 
                                            Foreground="{Binding Path=CompletedStatus, Converter={StaticResource ResourceKey=completeColorConvert}}"
                                            Tag="Some Value"
                                            Value="{Binding Path=CompletedStatus, Converter={StaticResource ResourceKey=completeConvert}}" 
                                            Maximum="100" Minimum="1" Height="25"
                                            Width="100">                                    
                                </ProgressBar>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="Delete"  Width="45" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Width="20" Height="20"  Foreground="White" Command="{Binding ElementName=todoVm, Path=DeleteAction}">
                                    <Button.Background>
                                        <ImageBrush ImageSource="..\\Image\delete.ico" />
                                    </Button.Background>
                                    <Button.CommandParameter>
                                        <MultiBinding Converter="{StaticResource ResourceKey=todoConvert}">
                                            <Binding  Path="Id"></Binding>
                                            <Binding  ElementName="todoVm"></Binding>
                                        </MultiBinding>
                                    </Button.CommandParameter>
                                </Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                    <GridViewColumn Header="Edit"  Width="45" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Button Width="20" Height="20"  Foreground="White" 
                                        Command="{Binding ElementName=todoVm, Path=EditAction}">
                                    <Button.Background>
                                        <ImageBrush ImageSource="..\\Image\edit.ico" />
                                    </Button.Background>
                                    <Button.CommandParameter>
                                        <MultiBinding Converter="{StaticResource ResourceKey=todoConvert}">
                                            <Binding  Path="Id"></Binding>
                                            <Binding  ElementName="todoVm"></Binding>
                                        </MultiBinding>
                                    </Button.CommandParameter>
                                </Button>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>

                </GridView>
            </ListView.View>
        </ListView>
         
    </StackPanel>
        
</Page>
